package com.starsea.book.ui.newpage.weidget.banner.transformer

import android.view.View
import androidx.core.view.ViewCompat

/**
 * 描述:
 */
class RotatePageTransformer : BannerPageTransformer {
  private var mMaxRotation = 15.0f

  constructor()
  constructor(maxRotation: Float) {
    setMaxRotation(maxRotation)
  }

  override fun handleInvisiblePage(view: View, position: Float) {
    ViewCompat.setPivotX(view, view.measuredWidth * 0.5f)
    ViewCompat.setPivotY(view, view.measuredHeight.toFloat())
    ViewCompat.setRotation(view, 0f)
  }

  override fun handleLeftPage(view: View, position: Float) {
    val rotation = mMaxRotation * position
    ViewCompat.setPivotX(view, view.measuredWidth * 0.5f)
    ViewCompat.setPivotY(view, view.measuredHeight.toFloat())
    ViewCompat.setRotation(view, rotation)
  }

  override fun handleRightPage(view: View, position: Float) {
    handleLeftPage(view, position)
  }

  fun setMaxRotation(maxRotation: Float) {
    if (maxRotation >= 0.0f && maxRotation <= 40.0f) {
      mMaxRotation = maxRotation
    }
  }
}